
package com.hmsg.health.dao;

import com.hmsg.health.bean.Dto.TaskDto;
import com.hmsg.health.bean.domain.MessageDo;
import com.hmsg.health.bean.domain.TaskDo;
import com.hmsg.health.bean.domain.UserDo;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface MessageDao {
	
    @Select("select * from s_message where id=#{id}")
    MessageDo findOne(@Param("id")Integer id);
    
    @Select("<script>" +
    	    "select * from  `s_message` where 1=1 " +
    	    "    <if test='info.id != null'>" +
    	    "     and `id` = #{info.id} " +
    	    "    </if>" +
    	
    	    "    <if test='info.isRead != null'>" +
    	    "    and  `is_read` = #{info.isRead} " +
    	    "    </if>" +
    	    "    <if test='info.resourceId != null'>" +
    	    "    and  `resource_id` = #{info.resourceId} " +
    	    "    </if>" +
    	    "    <if test='info.type != null'>" +
    	    "    and  `type` = #{info.type} " +
    	    "    </if>" +
    	    "    <if test='info.userId != null'>" +
    	    "    and  `user_id` = #{info.userId} " +
    	    "    </if>" +
    	 
    	    "    order by id desc" +
    	    "    <if test='info.startNo != null'>" +
    	    "      limit #{info.startNo},#{info.pageSize}" +
    	    "    </if>" +
    	    "</script>")
    List<MessageDo> select(@Param("info") MessageDo info);
    
   
    @Delete("delete from s_message where id=#{userId}")
    int delete(Integer userId);
    
  
    @Insert("<script>" +
    "insert into `s_message` " +
    "  <set>" +
    "    <if test='info.userId != null'>" +
    "     `user_id` = #{info.userId}, " +
    "    </if>" +
    "    <if test='info.createTime != null'>" +
    "      `create_time` = #{info.createTime}, " +
    "    </if>" +
    "    <if test='info.resourceId != null'>" +
    "      `resource_id` = #{info.resourceId}, " +
    "    </if>" +
    "    <if test='info.type != null'>" +
    "      `type` = #{info.type}, " +
    "    </if>" +
    "    <if test='info.title != null'>" +
    "      `title` = #{info.title}, " +
    "    </if>" +
    "    <if test='info.isRead != null'>" +
    "      `is_read` = #{info.isRead}" +
    "    </if>" +
    "  </set>" +
    "</script>")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	int save(@Param("info") MessageDo info);


    @Update({"<script>",
		"UPDATE  s_message",
		"<trim prefix='set' suffixOverrides=','>",
		
		"<if test='user.isRead!=null'>",
		"is_read= #{user.isRead}",
		"</if>",
	
		"</trim>",
		"where id = #{user.id}",
		"</script>"})
 	void update(@Param("user") MessageDo user);


}